package view;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

import model.Oneshape;

public class ShowPanel extends JPanel implements Observer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7313347441844463362L;
	private Oneshape nshape;
	public static final int WIDTH = 20;
	public static final int HEIGHT = 20;

	public ShowPanel() {
		setSize(200, 550);
		setLocation(400, 0);
		setBackground(Color.PINK);
		setBorder(BorderFactory.createEtchedBorder());

	}

	@Override
	public void paint(Graphics g) {
		Font font = new Font("幼圆", Font.LAYOUT_NO_LIMIT_CONTEXT, 20);
		super.paint(g);
		g.setFont(font);
		g.drawString("下个图形：", 20, 50);
		g.drawString("分数：", 30, 180);
		if (nshape == null)
			return;
		Color color = nshape.getColor();
		int[][] nextshape = nshape.getShape();
		for (int i = 0; i < nextshape.length; i++) {
			for (int j = 0; j < nextshape[i].length; j++) {
				if (nextshape[i][j] == 1) {
					g.setColor(color);
					g.fill3DRect(nshape.getX() + i * WIDTH, nshape.getY() + j * HEIGHT, WIDTH, HEIGHT, true);
				}
			}
		}

	}

	@Override
	public void update(Observable o, Object arg) {
		Oneshape os = (Oneshape) arg;
		if (os.isNext())
			this.nshape = (Oneshape) arg;
	}

}
